﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;
using System.Json;

namespace ToodledoAPI
{
    public struct TaskDetailsConfiguration
    {
        private bool FolderIncluded;
        public void IncludeFolder()
        {
            FolderIncluded = true;
        }

        private bool ContextIncluded;
        public void IncludeContext()
        {
            ContextIncluded = true;
        }

        private bool GoalIncluded;
        public void IncludeGoal()
        {
            GoalIncluded = true;
        }

        private bool LocationIncluded;
        public void IncludeLocation()
        {
            LocationIncluded = true;
        }

        private bool TagIncluded;
        public void IncludeTag()
        {
            TagIncluded = true;
        }

        private bool StartDateIncluded;
        public void IncludeStartDate()
        {
            StartDateIncluded = true;
        }

        private bool DueDateIncluded;
        public void IncludeDueDate()
        {
            DueDateIncluded = true;
        }

        private bool DueDateModIncluded;
        public void IncludeDueDateMod()
        {
            DueDateModIncluded = true;
        }

        private bool StartTimeIncluded;
        public void IncludeStartTime()
        {
            StartTimeIncluded = true;
        }

        private bool DueTimeIncluded;
        public void IncludeDueTime()
        {
            DueTimeIncluded = true;
        }

        private bool RemindIncluded;
        public void IncludeRemind()
        {
            RemindIncluded = true;
        }

        private bool RepeatIncluded;
        public void IncludeRepeat()
        {
            RepeatIncluded = true;
        }

        private bool StatusIncluded;
        public void IncludeStatus()
        {
            StatusIncluded = true;
        }

        private bool StarIncluded;
        public void IncludeStar()
        {
            StarIncluded = true;
        }

        private bool PriorityIncluded;
        public void IncludePriority()
        {
            PriorityIncluded = true;
        }

        private bool LengthIncluded;
        public void IncludeLength()
        {
            LengthIncluded = true;
        }

        private bool TimerIncluded;
        public void IncludeTimer()
        {
            TimerIncluded = true;
        }

        private bool AddedIncluded;
        public void IncludeAdded()
        {
            AddedIncluded = true;
        }

        private bool NoteIncluded;
        public void IncludeNote()
        {
            NoteIncluded = true;
        }

        private bool ParentIncluded;
        public void IncludeParent()
        {
            ParentIncluded = true;
        }

        private bool ChildrenIncluded;
        public void IncludeChildren()
        {
            ChildrenIncluded = true;
        }

        private bool OrderIncluded;
        public void IncludeOrder()
        {
            OrderIncluded = true;
        }

        private bool MetaIncluded;
        public void IncludeMeta()
        {
            MetaIncluded = true;
        }

        private bool this[string PropertyName]
        {
            get
            {
                switch (PropertyName)
                {
                    case "folder":
                        return FolderIncluded;
                    case "context":
                        return ContextIncluded;
                    case "goal":
                        return GoalIncluded;
                    case "location":
                        return LocationIncluded;
                    case "tag":
                        return TagIncluded;
                    case "startdate":
                        return StartDateIncluded;
                    case "duedate":
                        return DueDateIncluded;
                    case "duedatemod":
                        return DueDateModIncluded;
                    case "starttime":
                        return StartTimeIncluded;
                    case "duetime":
                        return DueTimeIncluded;
                    case "remind":
                        return RemindIncluded;
                    case "repeat":
                        return RepeatIncluded;
                    case "status":
                        return StatusIncluded;
                    case "star":
                        return StarIncluded;
                    case "priority":
                        return PriorityIncluded;
                    case "length":
                        return LengthIncluded;
                    case "timer":
                        return TimerIncluded;
                    case "added":
                        return AddedIncluded;
                    case "note":
                        return NoteIncluded;
                    case "parent":
                        return ParentIncluded;
                    case "children":
                        return ChildrenIncluded;
                    case "order":
                        return OrderIncluded;
                    case "meta":
                        return MetaIncluded;
                    //The following are all always included by toodledo
                    case "id":
                    case "title":
                    case "modified":
                    case "completed ":
                        return true;
                    default:
                        throw new ArgumentException("This is not a valid property name");
                }
            }
        }

        internal string fields()
        {
            string[] AllFieldNames = new string[] { "folder", "context", "goal", "location", "tag", "startdate", "duedate", "duedatemod", "starttime", "duetime", "remind", "repeat", "status", "star", "priority", "length", "timer", "added", "note", "parent", "children", "order", "meta" };
            StringBuilder Output = new StringBuilder();
            foreach (string field in AllFieldNames)
            {
                if (this[field])
                {
                    if (Output.Length == 0)
                        Output.Append(field);
                    else
                        Output.Append("," + field);
                }
            }
            return Output.ToString();
        }

        internal T LoadField<T>(JsonObject jsonObject, string PropertyName, Func<string, T> Parse)
        {
            if (this[PropertyName])
            {
                return Parse(jsonObject[PropertyName]);
            }
            else
            {
                return default(T);
            }
        }
    }
}
